package com.bw.web;
import com.bw.bean.Admin;
import com.bw.dao.UserDao;
import com.bw.dao.UserDaoImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author admin
 * @date 2025年08月25日 20:02
 */
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {

    UserDao dao = new UserDaoImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //转换乱码
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");

        //获取页面值
        String uname = req.getParameter("uname");
        System.out.println(uname);
        String pwd = req.getParameter("pwd");
        System.out.println(pwd);

        //反馈回页面
        resp.getWriter().println("进入到servlet 方法中");
        resp.getWriter().println("\n用户："+uname);
        resp.getWriter().println("密码："+pwd);

        Admin admin=dao.login(uname,pwd);

        //判断该值是否存在于数据库
        if(admin!=null){
            resp.getWriter().println("\n登录成功啦！！！");
        }else {
            resp.getWriter().println("\n登录失败啦！！！");
        }
    }
}
